const express = require('express');
const authRoute = require('./auth.route');
const userRoute = require('./user.route');
const adminRoute = require('./admin');
const foodRoute = require('./food.route');
const searchHistoryRoute = require('./searchHistory.route');
const activityLogRoute = require('./activityLog.routes');
const nutritionRoute = require('./v1/nutrition.route');
const settingsRoute = require('./v1/settings.route');
const dashboardRoute = require('./v1/dashboard.route');
const docsRoute = require('./docs.route');
const config = require('../config/config');

const router = express.Router();

const defaultRoutes = [
  {
    path: '/auth',
    route: authRoute,
  },
  {
    path: '/user',
    route: userRoute,
  },
  {
    path: '/admin',
    route: adminRoute,
  },
  {
    path: '/foods',
    route: foodRoute,
  },
  {
    path: '/search-history',
    route: searchHistoryRoute,
  },
  {
    path: '/activity-logs',
    route: activityLogRoute,
  },
  {
    path: '/nutrition',
    route: nutritionRoute,
  },
  {
    path: '/v1/settings',
    route: settingsRoute,
  },
  {
    path: '/dashboard',
    route: dashboardRoute,
  },
];

const devRoutes = [
  // 只在开发环境中可用的路由
  {
    path: '/docs',
    route: docsRoute,
  },
];

defaultRoutes.forEach((route) => {
  router.use(route.path, route.route);
});

// 只在开发和测试环境中加载开发路由
if (config.env === 'development' || config.env === 'test') {
  devRoutes.forEach((route) => {
    router.use(route.path, route.route);
  });
}

module.exports = router; 